package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by utsabban on 2/25/14.
 */
public class Book {
    private String bookName;
    private Integer currentQuantity;
    private final Integer maxQuantity;
    private List<String> borrowerList;


    Book(String bookName, Integer currentQuantity, Integer maxQuantity)
    {
        this.bookName=bookName;
        this.maxQuantity = maxQuantity;
        this.currentQuantity=currentQuantity;
        borrowerList=new ArrayList<String>();
    }

    public String toString()
    {
        return getBookName()+" "+getCurrentQuantity()+" "+maxQuantity+" "+borrowerList.toString();
    }

    public String getBookName()
    {
        return bookName;
    }

    public Integer getCurrentQuantity() { return currentQuantity; }

    public boolean bookCheckout(String bookToCheckout,String borrowerCustomerNumber)
    {
        if(!bookName.equals(bookToCheckout))
            return false;
        if(currentQuantity>0)
            currentQuantity--;
        else
            return false;
        borrowerList.add(borrowerCustomerNumber);
        return true;
    }

    public boolean bookReturn(String bookToReturn,String borrowerCustomerNumber)
    {
        if(!bookName.equals(bookToReturn))
            return false;
        if(borrowerList.contains(borrowerCustomerNumber) && currentQuantity<maxQuantity)
            currentQuantity++;
        else
            return false;
        borrowerList.remove(borrowerCustomerNumber);
        return true;
    }

    public List<String> returnBorrowers()
    {
        return borrowerList;
    }
}
